package com.bite.bite_forum.common;


import com.fasterxml.jackson.annotation.JsonInclude;

public class AppResult<T> {
    @JsonInclude
    private long code;
    @JsonInclude
    private String message;
    @JsonInclude
    private T data;

    public long getCode() {
        return code;
    }

    public void setCode(long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public AppResult(){};

    public AppResult(long code, String message){
        this.code = code;
        this.message = message;
    }
    public AppResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    /*
    成功
     */
    public static AppResult success(){
        return new AppResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }

    //返回结果
    public static <T> AppResult<T> success(T data){
        return new AppResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),
                data);
    }

    //自定义信息
    public static <T> AppResult<T> success(String message, T data){
        return new AppResult<>(ResultCode.SUCCESS.getCode(), message, data);
    }

    /*
    失败返回结果
     */
    public static AppResult failed(){
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }

    public static AppResult failed(String message){
        return new AppResult(ResultCode.FAILED.getCode(), message);
    }

    public static<T> AppResult<T> failed(T data){
        return new AppResult<>(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), data);
    }

    public static AppResult failed(ResultCode resultCode){
        return new AppResult(resultCode.getCode(), resultCode.getMessage());
    }

}
